<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>bui-ssm快速开发框架</title>
    <head th:include="source::header"></head>
    <style>
			body {
				position: relative;
			}
			
			body > div {
				width: 100%;
				height: 100%;
				position: absolute;
				top: 0;
				left: 0;
			}
    </style>
</head>
<body>
<div id="header">
    <h5><div class="header_logo"></div>bui-ssm快速开发框架 v-0.0.1</h5>
    <div id="user_info">[(${loginUser})]</div>
    <div id="logout" th:title="${Lang.common_logout}">
    	<i class="fa fa-logout-1"></i>
    </div>
</div>
<div id="main_body" class="k_box_size"></div>
</body>
<script type="application/javascript">
    function pageLoaded() {
    	var menuJson = [(${menuJson})];
    	console.log(menuJson);
		var itemsAcc = [];
    	for(var i = 0, len = menuJson.length ; i < len ;++i){
    		var ul = $("<ul/>");
    		itemsAcc.push({
                name: menuJson[i].text,
                icon: menuJson[i].data.menuIconCss,
                content: ul
            });
    		if(menuJson[i].children){
                new $B.Tree(ul, {
                    data: menuJson[i].children, //'数据'
                    checkbox: false,
                    fontIconColor: '#5F52E3',
                    nodeParentIcon: 'fa-folder-empty', //父节点图标关闭状态
                    nodeParentOpenIcon: 'fa-folder-open-empty', //打开状态图标
                    leafNodeIcon: 'fa-doc', //子节点图标 
                    onClick: function (data, params) { //function (data) { },//点击事件           
                    	var menuData = this.children().data("data");
                    	var _data =  menuData.data;
                    	console.log(_data);
                    	if(_data.isLeaf === 1){
                        	var url = $B.getHttpHost(ctxPath) + _data.controller+"/page/"+_data.pageName ;
                        	if(_data.params && _data.params !== ""){
                        		url = url + "?"+ _data.params;
                        	}
                            layout.load({
                            	iconCls: _data.menuIconCss,
                                url: url, //url地址
                                dataType: 'iframe',
                                title: menuData.text
                            }, 1);
                    	}
                    }
                });
    		}
    	}
    	if(itemsAcc.length > 0){
            var accordion = $("<div id='memu_accordion'></div>");
            var layout = new $B.Layout($("#main_body"), {
                onCreated: function (params) { //function(){} 布局创建完成事件,
                    console.log("onCreated " + JSON.stringify(params));
                },
                onLoaded: function (data, params) { //加载完成
                    console.log("onLoaded data = " + JSON.stringify(data) + " params=" + JSON.stringify(
                        params));
                },
                items: [ //参考items说明
                    {
                        width: 230,
                        title: '系统面板', //标题
                        expandable: true,
                        iconCls: 'fa-cog-alt', //样式
                        content: accordion
                    }, {
                        header: true, //是否需要标题栏
                        iconCls: 'fa-file-code',
                        width: 'auto', //宽度
                        title: '页面模块',
                        bodyCss:{"padding":"10px 10px"}
                    }
                ]
            });
            //创建菜单项目
            var opts = {
                iconCls: 'fa-angle-double-right', //收起图标
                iconClsAct: 'fa-angle-double-down', //展开图标
                iconPositon: 'right', //图标位置
                iconColor: '#666666', //图标颜色
                onOpened: function (name) {
                    //console.log(name + "  onOpened " + this[0].outerHTML);
                    this.children("ul").children("li").first().trigger("click");
                },
                accordionStyle: {
                    "background": "#F6F6F6",
                    "border": "1px solid #C5C5C5",
                    "border-right": "none",
                    "border-left": "none"
                },
                items: itemsAcc
            };
            accordion = new $B.Accordion(accordion, opts);
    	}else{
    		$B.error({
    			message:'尚未登录或无访问权限!' ,
    			timeout:3,
    			onClosed:function(){
    				window.location.href = $B.getHttpHost(ctxPath)+"main/page/login";
    			}
    		});	
    	}        
        $("#logout").click(function(){
        	  $B.confirm({                  
                  message: '请确认退出系统？',
                  okFn: function () {
                  	var win = $B.message("正在退出......");
        			$B.request({
        				url:$B.getHttpHost(ctxPath)+"main/logout",
        				data:{},
        				ok:function(msg,data){					
        					window.location.href = $B.getHttpHost(ctxPath)+"main/page/login";
        				},
        				final:function(){
        					win.close();
        				}
        			});
                  }
              });
        });
    };
    $(function () {
        pageLoaded();
    });
</script>
</html>